<?php
namespace modules\iChat\controllers;

use controllers\BaseController;
use modules\iChat\services\HomeService;
use modules\iChat\iChatException;

class UserController extends BaseController
{
	//参数检测
	public function getParamRules()
	{
		return [
			'actionLogin'     =>  ['numeric' => 'uid', 'passWord'],
			'actionLogout'    => ['token'],
			'actionHandle'    => ['token'],
			'actionAddFriend' => ['token', 'aid', 'uid'],
			'actionChatList'  => ['token', 'uid'],
			'actionDetail'    => ['token', 'uid'],
		];
	}
	public function actionLogin()
	{
		$uid   = $this->params['uid'];
		$pwd   = $this->params['passWord'];
		$data  = HomeService::login($uid, $pwd);
		return $data;
	}

	public function actionLogout()
	{
		$token = $this->params['token'];
		HomeService::logout($token);
		return [];
	}
	
	// public function actionHandle()
	// {
	// 	$method = $this->params['method'];
	// 	HomeService::execute($method, $this->params);
	// 	return [];
	// }

	public function actionRegister()
	{
		$info = [
			'userName' => 'zhangxiao',
			'passWord' => '123456',
			'uid'      => '18612402834',
			'headPhoto' => 'image/1.jpg',
			'time'     => time(),
		];
		$info2 = [
			'userName' => 'hanhan',
			'passWord' => '123456',
			'uid'      => '13122762997',
			'headPhoto' => 'image/3.jpg',
			'time'     => time(),
		];
		$info1 = [
			'userName' => 'keer',
			'passWord' => '123456',
			'uid'      => '15600586798',
			'headPhoto' => 'image/4.jpg',
			'time'     => time(),
		];
		$uid = $info['uid'];
		HomeService::register($uid, $info);
		return $info;
	}

	public function actionAddFriend()
	{
		$token    = $this->params['token'];
		$aid      = $this->params['aid'];
		$uid      = $this->params['uid'];
		HomeService::addFriend($token, $uid, $aid);
		return [];
	}

	public function actionChatList()
	{
		$token = $this->params['token'];
		$uid   = $this->params['uid'];
		$data  = HomeService::getChatList($token, $uid);
		return $data;
	}

	public function actionFriendList()
	{
		$token = $this->params['token'];
		$uid   = $this->params['uid'];
		$data  = HomeService::getFriendList($token, $uid);
		return $data;
	}

	public function actionTestWriteUserMessage()
	{
		HomeService::testWriteUser();
		return [];
	}
}
